package com.org.gsc.chartdemo.activitys;

import android.graphics.Color;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.org.gsc.chartdemo.MyMarkerView;
import com.org.gsc.chartdemo.R;
import com.org.gsc.chartdemo.bases.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qundui on 2017/8/29.
 * 柱状图页面
 */
public class BarAcivity extends BaseActivity {
    private BarChart barChart;
    private BarData mbardata;
    private BarDataSet m成绩;
    private LimitLine m及格分数线;

    @Override
    protected void doBusy() {
         barChart = (BarChart) findView(R.id.chart_bar);
        //获取X轴
        XAxis xAxis = barChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        barChart.getDescription().setEnabled(false);
        xAxis.setDrawGridLines(false);
        //获取X 轴的自定义格式器
        xAxis.setGranularity(1f);//设置最小间隔，防止当放大时，出现重复标签。
        XAxisValueFormatter xAxisValueFormatter=new XAxisValueFormatter(barChart);
        xAxis.setValueFormatter(xAxisValueFormatter);
        //获取Y轴以及自定义的构造器
        barChart.getAxisRight().setEnabled(false);
        barChart.getAxisLeft().setDrawGridLines(false);
        barChart.getAxisLeft().setValueFormatter(new YAxisValueFormatter());
        m及格分数线 = new LimitLine(60f, "及格分数线");
        m及格分数线.setTextColor(Color.RED);
        barChart.getAxisLeft().addLimitLine(m及格分数线);
//        List<Float> scores=new ArrayList<>();
//        scores.add(23.5f);
//        scores.add(45f);
//        scores.add(78f);
        MyMarkerView myMarkerView=new MyMarkerView(this, R.layout.custom_marker_view);
        myMarkerView.setChartView(barChart);
        barChart.setMarker(myMarkerView);
        List<IBarDataSet> datasets=new ArrayList<>();
        List<BarEntry> y=new ArrayList<>();
        y.add(new BarEntry(0,30));

        y.add(new BarEntry(1,56));
        y.add(new BarEntry(2,78));
        y.add(new BarEntry(3,80));
        y.add(new BarEntry(4,90));
        myMarkerView.setClipChildren(false);
        m成绩 = new BarDataSet(y, "成绩");
        // m成绩.setColor(Color.GREEN);
        m成绩.setColors(ColorTemplate.MATERIAL_COLORS);
        datasets.add(m成绩);
        barChart.setData(new BarData(datasets));
//        scores.add(90f);
//        YAxisValueFormatter yAxisValueFormatter=new YAxisValueFormatter(scores);
//        axisLeft.setValueFormatter(yAxisValueFormatter);
    }
    @Override
    protected int getLayoutId() {
        return R.layout.act_bar;
    }
}
